/*
 * name: mabel xu
 * date: february 25, 2008
 * filename: StudentReader.java
 * description: reads data about students from file ... to declutter main program
 */

import java.io.*;	// File
import java.util.*;	// Scanner

public class StudentReader
{
	Scanner s;

	// try to create the scanner
	public StudentReader(String loc) throws FileNotFoundException, IOException
	{
		s = new Scanner(new File(loc));
	}	// end constructor

	// get students to be added
	public ArrayList<StudentID> getAdds(String stopword)
	{
		ArrayList<StudentID> data = new ArrayList<StudentID>();

		String first = s.nextLine();
		while (!first.equals(stopword))	// keep going until told to stop
		{
			String last = s.nextLine();
			Integer id = new Integer(s.nextInt()); s.nextLine();
			String addr = s.nextLine();
			String city = s.nextLine();
			String state = s.nextLine();
			Integer zip = new Integer(s.nextInt()); s.nextLine();
			String phone = s.nextLine();

			data.add(new StudentID(first, last, id, addr, city, state, zip, phone));

			first = s.nextLine();
		}		// end loop to populate data arraylist

		return data;
	}		// end getAdds method

	// get students to be changed
	public ArrayList<StudentID[]> getChanges(String stopword)
	{
		ArrayList<StudentID[]> data = new ArrayList<StudentID[]>();

		String oFirst = s.nextLine();
		while (!oFirst.equals(stopword))	// keep going until told to stop
		{
			String oLast = s.nextLine();
			Integer oId = new Integer(s.nextInt()); s.nextLine();
			String nFirst = s.nextLine();
			String nLast = s.nextLine();
			Integer nId = new Integer(s.nextInt()); s.nextLine();
			String nAddr = s.nextLine();
			String nCity = s.nextLine();
			String nState = s.nextLine();
			Integer nZip = new Integer(s.nextInt()); s.nextLine();
			String nPhone = s.nextLine();

			StudentID[] temp = {new StudentID(oFirst, oLast, oId, null, null, null, null, null),
								new StudentID(nFirst, nLast, nId, nAddr, nCity, nState, nZip, nPhone)};
			data.add(temp);

			oFirst = s.nextLine();
		}		// end of while loop to get changes

		return data;
	}		// end of getChanges method

	// get students to be removed
	public ArrayList<StudentID> getRemoves(String stopword)
	{
		ArrayList<StudentID> data = new ArrayList<StudentID>();

		String first = s.nextLine();
		while (!first.equals(stopword))	// keep getting removes until told to stop
		{
			String last = s.nextLine();
			Integer id = new Integer(s.nextInt()); s.nextLine();

			data.add(new StudentID(first, last, id, null, null, null, null, null));

			first = s.nextLine();
		}		// end of loop to keep getting removes

		return data;
	}		// end getRemoves method

	// get students to be found
	public ArrayList<StudentID> getFinds(String stopword)
	{
		ArrayList<StudentID> data = new ArrayList<StudentID>();

		String first = s.nextLine();
		while (!first.equals(stopword))	// keep going until all students read
		{
			String last = s.nextLine();
			Integer id = new Integer(s.nextInt()); s.nextLine();

			data.add(new StudentID(first, last, id, null,null, null, null, null));

			first = s.nextLine();
		}		// end of loop to get students to be found

		return data;
	}		// end of getFinds method
}		// end of StudentReader class